import DictionaryConstants from "@/const/DictionaryConstants.ts";
import instance from "@/api/request.ts";

const ApiConst = DictionaryConstants.ApiConst;
/**
 * 添加商品到购物车
 * @param skuId 商品skuId
 * @param num 购买数量
 */
export const addProductToCart = (skuId: number, num: number) => {
    return instance.post(`${ApiConst.CART}/cart/`, {
        skuId,
        num,
    });
};

/**
 * 批量删除购物车中的商品
 *
 * @param skuIds 商品skuId集合
 */
export const deleteProductFromCartBatch = (skuIds: number[]) => {

    console.log(skuIds);
    return instance.delete(`${ApiConst.CART}/cart/`, {
        params: {
            ids: skuIds,
        },
    });
};

/**
 * 获取购物车商品列表
 * @param isShowMessage 是否显示消息提示
 */
export const getCartInfoList = (isShowMessage: boolean) => {


    return instance.get(`${ApiConst.CART}/cart/`, {
        headers: {
            IS_SHOW_MESSAGE: isShowMessage,
        },
    });
};

/**
 * 修改购物车商品数量
 * @param skuId 商品skuId
 * @param count
 */
export const updateProductFromCart = (skuId: number, count: number) => {
    return instance.put(`${ApiConst.CART}/cart/`, {
        skuId,
        count,
    });
};